import sys
import os

### Stuff you might want to change ###

LIBRARY_SOURCES = [
    'src/Game.cpp',
    'src/Menu/MenuPage.cpp',
    'src/Menu/MainMenuPage.cpp',
    'src/Menu/OptionsPage.cpp',
    'src/Menu/OptionPage.cpp',
    'src/Menu/OptionItem.cpp',
    'src/Menu/MenuItem.cpp',
    'src/Menu/StartGameMenuItem.cpp',
    'src/Menu/DummyMenuItem.cpp',
    'src/Menu/MoveMenu.cpp',
    'src/Menu/LinkTo.cpp',
    'src/Menu/Exit.cpp',
    'src/GameLoop.cpp',
    'src/Ship.cpp',
    'src/Engine.cpp',
    'src/Shield.cpp',
    'src/Player.cpp',
    'src/HumanPlayer.cpp',
    'src/WorldObject.cpp',
    'src/World.cpp',
    'src/Input/Checker.cpp',
    'src/Input/Input.cpp',
    'src/Map.cpp',
    'src/MapObstacle.cpp',
    'src/HUD.cpp',
    'src/Console.cpp',
    'src/Minimap.cpp',
    'src/Explosion.cpp',
    'src/Shockwave.cpp',
    'src/Flag.cpp',
    'src/Team.cpp',
    'src/Settings.cpp',
    'src/GameState.cpp',
    'src/Utils/Vector2D.cpp',
    'src/Utils/Timer.cpp',
    'src/Graphics/GraphicsBase.cpp',
    'src/Graphics/TextureManager.cpp',
    'src/Graphics/Font.cpp',
    'src/Graphics/ParticleSystem/Particle.cpp',
    'src/Graphics/ParticleSystem/ParticleEmitter.cpp',
    'src/Graphics/ParticleSystem/OneTimeParticleEmitter.cpp',
    'src/Graphics/ParticleSystem/OneTimeLinearParticleEmitter.cpp',
    'src/Graphics/ParticleSystem/ParticleSystem.cpp',
    'src/Graphics/ParticleSystem/SphereRepulsorModifier.cpp',
    'src/Graphics/ParticleSystem/PointAttractorModifier.cpp',
    'src/Weapons/Blaster.cpp',
    'src/Weapons/Railgun.cpp',
    'src/Weapons/Afterburner.cpp',
    'src/Weapons/Bomb.cpp',
    'src/PowerUp/SpeedPowerUp.cpp',
    'src/AI/RRT.cpp',
    'src/AI/AIPlayer.cpp',
    'src/AI/RoleAssigner.cpp',
    'src/AI/AttackerRole.cpp',
    'src/AI/DefenderRole.cpp',
    'src/AI/MarauderRole.cpp',
    'src/AI/CommonBehaviours.cpp',
    'src/AI/PathFindBehaviour.cpp',
    'src/AI/DogFightBehaviour.cpp',
    'src/AI/GetEnemyFlag.cpp',
    'src/AI/ReturnEnemyFlag.cpp',
    'src/AI/LoiterBehaviour.cpp',
    'src/Sound/Sound.cpp'
]

BINARY_SOURCES = ['src/main.cpp']

DIST_SOURCES = LIBRARY_SOURCES + [
    'src/Game.h',
    'src/Menu/MenuPage.h',
    'src/Menu/MainMenuPage.h',
    'src/Menu/OptionsPage.h',
    'src/Menu/OptionPage.h',
    'src/Menu/OptionItem.h',
    'src/Menu/MenuItem.h',
    'src/Menu/StartGameMenuItem.h',
    'src/Menu/DummyMenuItem.h',
    'src/Menu/MoveMenu.h',
    'src/Menu/LinkTo.h',
    'src/Menu/Exit.h',
    'src/GameLoop.h',
    'src/Ship.h',
    'src/Engine.h',
    'src/Shield.h',
    'src/Player.h',
    'src/HumanPlayer.h',
    'src/PowerUp.h',
    'src/WorldObject.h',
    'src/World.h',
    'src/Input/Checker.h',
    'src/Input/Input.h',
    'src/Map.h',
    'src/MapObstacle.h',
    'src/HUD.h',
    'src/Console.h',
    'src/Minimap.h',
    'src/Explosion.h',
    'src/Shockwave.h',
    'src/Flag.h',
    'src/Team.h',
    'src/Settings.h',
    'src/GameState.h',
    'src/Utils/Vector2D.h',
    'src/Utils/Util.h',
    'src/Utils/Timer.h',
    'src/Graphics/GraphicsBase.h',
    'src/Graphics/TextureManager.h',
    'src/Graphics/Font.h',
    'src/Graphics/ParticleSystem/Particle.h',
    'src/Graphics/ParticleSystem/ParticleEmitter.h',
    'src/Graphics/ParticleSystem/OneTimeParticleEmitter.h',
    'src/Graphics/ParticleSystem/OneTimeLinearParticleEmitter.h',
    'src/Graphics/ParticleSystem/ParticleSystem.h',
    'src/Graphics/ParticleSystem/ParticleModifier.h',
    'src/Graphics/ParticleSystem/SphereRepulsorModifier.h',
    'src/Graphics/ParticleSystem/PointAttractorModifier.h',
    'src/Weapons/Weapon.h',
    'src/Weapons/Blaster.h',
    'src/Weapons/Railgun.h',
    'src/Weapons/Afterburner.h',
    'src/Weapons/Bomb.h',
    'src/PowerUp/Spawner.h',
    'src/PowerUp/PowerUp.h',
    'src/PowerUp/SpeedPowerUp.h',
    'src/AI/RRT.h',
    'src/AI/AIPlayer.h',
    'src/AI/RoleAssigner.h',
    'src/AI/AttackerRole.h',
    'src/AI/DefenderRole.h',
    'src/AI/MarauderRole.h',
    'src/AI/CommonBehaviours.h',
    'src/AI/PathFindBehaviour.h',
    'src/AI/DogFightBehaviour.h',
    'src/AI/GetEnemyFlag.h',
    'src/AI/ReturnEnemyFlag.h',
    'src/AI/LoiterBehaviour.h',
    'src/Sound/Sound.h'
]

LIBS = ['GL', 'GLU', 'SDL_image', 'SDL_sound']

release_flags = '-Wall -Werror -D_REENTRANT -O3'
debug_flags = '-Wall -Werror -D_REENTRANT -g -DDEBUG'
sdl_flags = os.popen("sdl-config --libs").read()
sdl_flags = sdl_flags.rstrip()

### Stuff you probably don't need to change ###

env = Environment()
mode = ARGUMENTS.get('wasd', 'rel')
if mode == 'rel':
    release_flags = release_flags + ' -DWASD_REL '
    debug_flags = debug_flags + ' -DWASD_REL '
elif mode == 'abs':
    release_flags = release_flags + ' -DWASD_ABS '
    debug_flags = debug_flags + ' -DWASD_ABS '

mode = ARGUMENTS.get('mode', 'debug')
if mode == 'debug':
    env.Append(CXXFLAGS = debug_flags)
elif mode == 'release':
    env.Append(CXXFLAGS = release_flags)
else:
    print "Unknown mode '%s%', use debug (default) or release" % mode
    sys.exit(1)

### compilation rules
library_objects = [ env.Object(s, CXX = 'g++') for s in LIBRARY_SOURCES]
binary_objects = [ env.Object(s, CXX = 'g++') for s in BINARY_SOURCES]

alife = env.Program('ctf', library_objects + binary_objects,
                        CXX = 'g++', LINKFLAGS = sdl_flags, LIBS = LIBS)
